$(function () {
	provinceInfo.baseURL = baseURL;
	provinceInfo.divId = "test";
	provinceInfo.init();
	provinceInfo.bindEvent();
    $("#form-add").Validform({
        tiptype: 1,
        showAllError: true,
        datatype: {
            "empty": /^\s*$/,
            "code": /^[a-z0-9A-Z_-]{1,16}$/
        },
        callback: function (form) {
            layer.confirm('您确定要提交表单吗?', function () {
                _submit();
            })
            return false;
        }
    });
})

_submit = function () {
    var data = {};
    data.provincecode = $('#_province').attr('name');
	data.citycode = $('#_city').attr('name');
    data.province = $('#_province').val();
	data.city = $('#_city').val();
    data.username = $('#usename').val();
    data.source = engineerSource($('#source').val());
    data.name = $('#name').val();
    data.sex = $('#sex').val();
    data.mobile = $('#mobile').val();
    data.qq = $('#qq').val();
    data.email = $('#email').val();
    data.company = $('#company').val();
    data.companyAddress = $('#companyAddress').val();
    data.clientRemark = $('#clientRemark').val();
    function engineerSource(obj){
    	if(obj=="论坛"){
    		return "1";
    	}else return "2";
    }
    $.ajax({
        type: "post",
        url: baseURL+"/api/member/saveOrgUpdateEngineer",
        dataType: "json",
        contentType: "application/json;charset=UTF-8", 
        data: JSON.stringify(data),
        success: function (result) {
            if (!result.flag) {
                layer.msg("增加失败！原因：" + result.message);
                return;
            }
            parent.location.reload();
            window.close();
        },
        error:function(errormsg){
			alert("数据出错："+JSON.stringify(errormsg));
		}
    });
}